#include <cctype>
#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

bool is_alpha(string & word){
    for(auto & s : word){
        if(!isalpha(s)){
            return false;
        }
    }
    return true;
}

class Record{
public:
    Record(const string & word,size_t frequency)
        :_word(word)
         ,_frequency(frequency)
    {

    }
    string _word;
    size_t _frequency;
};

class Dictionary{
public:
    void read(const string & filename){
        ifstream ifs(filename);
        if(!ifs){
            cerr << "file is not found" << endl;
            return;
        }

        string word;
        while(ifs >> word){
            if(is_alpha(word)){
                int i;
                for(i = 0; i < _dict.size(); ++i){
                    if(_dict[i]._word == word){
                        ++_dict[i]._frequency;
                        break;
                    }
                }
                if(i == _dict.size()){
                    Record record(word,1);
                    _dict.push_back(record);
                }
            }
        }
    }

    void store(const string & filename){
        ofstream ofs(filename);
        for(int i = 0;i < _dict.size();++i){
            ofs << _dict[i]._word << " " << _dict[i]._frequency << endl;
        }
    }

private:
    vector<Record> _dict;
};

void test(){
    Dictionary dict;
    dict.read("The_Holy_Bible.txt");
    dict.store("bible.txt");
}

int main()
{
    test();
    return 0;
}

